package ru.pb.game.network.engine.client.packets.receivable;

import ru.pb.game.network.engine.client.packets.FromClientToGameServerPacket;
import ru.pb.game.network.engine.client.packets.sendable.PROTOCOL_SHOP_LEAVE_ACK;
import ru.pb.game.objects.model.players.Player;
import ru.pb.game.objects.model.players.enums.SLOT_STATE;
import ru.pb.global.network.utils.NetworkUtil;

public class PROTOCOL_SHOP_LEAVE_REQ extends FromClientToGameServerPacket
{
	/**
	 * i3NetworkPacket__SetProtocol(&v223, 3331);
	 * i3NetworkPacket__WriteData(&v223, a3, 4);
	 * v138 = *(_DWORD *)a3;
	 * if ( v138 & 1 )
	 * {
	 * v137 = 0;
	 * v136 = 0;
	 * v135 = 0;
	 * v134 = 0;
	 * v133 = 0;
	 * sub_475370(SLODWORD(dword_A9AE78), (int)&v133);
	 * i3NetworkPacket__WriteData(&v223, &v133, 20);
	 * }
	 * if ( v138 & 2 )
	 * {
	 * sub_475240(v32, (int)&v132);
	 * i3NetworkPacket__WriteData(&v223, &v132, 20);
	 * }
	 * break;
	 */
	private int _v;

	public PROTOCOL_SHOP_LEAVE_REQ()
	{
		
	}

	@Override
	public void readImpl()
	{
		readH(); // frost
		_v = readD();
		_log.info("unkD: " + _v);
		if(_buf.hasRemaining())
			_log.info(NetworkUtil.printData(readB(_buf.remaining())));

	}

	@Override
	public void runImpl()
	{
		Player p = getPlayer();
		if(p != null)
		{
			if(p.getRoom() != null)
				p.getRoom().changeSlotState(p.getSlot(), SLOT_STATE.SLOT_STATE_NORMAL);
			p.sendPacket(new PROTOCOL_SHOP_LEAVE_ACK());
		}
	}
}
